package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.common.result.ResultCodeEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Date:2024/9/23 10:14
 * Author:ybc
 * Description:
 */
//@ControllerAdvice
@RestControllerAdvice //@ControllerAdvice+@ResponseBody
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    //@ResponseBody
    public Result error(Exception e){
        //e表示控制器方法出现的异常
        e.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler(LeaseException.class)
    public Result error(LeaseException leaseException){
        System.out.println(leaseException);
        return Result.build(null, leaseException.getCode(), leaseException.getMessage());
    }

}
